{% extends "cmdb/mbusiness/index.html" %}
{% block right_content %}

<div id="right_menu">
    <div>
        <form class="form-inline" style="float: right">
            <div class="form-group">
                <label for="category">分类</label>
                <select class="form-control" id="category">
                    <option value="all">全部</option>
                    {% for idx,single_category in category_list.items %}
                    {% ifnotequal single_category.parent_category 0 %}
                    <option  value="{{ idx }}" {% ifequal category idx %} selected {% endifequal %}>{{ single_category.parent_category_name }}-{{ single_category.category_name }}</option>
                    {% endifnotequal %}
                    {% endfor %}
                </select>
            </div>
            <div class="form-group">
                <label class="sr-only" for="search">Search</label>
                <input type="search" class="form-control" id="search" placeholder="模块名" value="{{ search }}" style="width:100%">
            </div>
            <button type="button" class="btn btn-primary" id="searchModule">查询</button>
        </form>
    </div>
    <table id="example" style="table-layout:fixed;" class="table table-bordered table-hover">
        <thead >
        <td class="col">模块编号</td>
        <td class="col">模块名</td>
        <td class="col">所属分类名</td>
        <td class="col">父分类</td>
        <td class="col">项目/业务</td>
        <td class="col">负责人</td>
        <td class="col">操作</td>
        </thead>
        {% if module_list %}
        {% for module in module_list %}
        <tr>
            <td class="col">{{ module.module_no }}</td>
            <td class="col">{{ module.module_name }}</td>
            <td class="col">{{ module.category_name }}</td>
            <td class="col">{{ module.parent_category_name }}</td>
            <td class="col">{{ module.project }}</td>
            <td class="col">{{ module.responser }}</td>
            <td class="col">
                <div>
                    <a class="edit_item hint hint-top mouse_pointer" data-hint="编辑业务模块" data-bno="{{ module.module_no }}" data-toggle="modal" data-target="#editItem">
                        <span class="glyphicon glyphicon-edit"></span>
                    </a>&nbsp;
                    <a class="hint hint-top mouse_pointer" data-hint="查看业务模块" data-bno="{{ module.module_no }}" data-toggle="modal" data-target="#lookItem">
                       <span class="glyphicon glyphicon-eye-open"></span> 
                    </a>&nbsp;
                    <a data-hint="删除业务模块" data-id="{{ module.id }}" data-bno="{{ module.module_no }}" class="delete_item hint hint-top mouse_pointer" data-hint="删除业务模块">
                        <span class="glyphicon glyphicon-trash"></span>
                    </a>
                </div>
            </td>
        </tr>
        {% endfor %}
        {% endif %}
    </table>

    <div>
        <span>跳转到
         <select class="pagei">
             {% for temppage in page_list %}
             <option value="{{ temppage }}" {% ifequal temppage page %}selected {% endifequal %}>{{ temppage }}</option>
             {% endfor %}
         </select>页
        </span>
        <span style="padding-left: 28%;">每页{{ page_num }}条，第{{ page }}页，共{{ count }}条，共{{ page_total }}页</span>

        <span style="float:right;padding-right:50px">

            <a class="word hint hint-top" data-hint="首页" href="{% url 'business:moduleinfo' %}?page=1&category={{ category }}&search={{ search }}"><span class="glyphicon glyphicon-fast-backward"></span></a>
            {% ifnotequal page 1 %}&nbsp;
            <a href="{% url 'business:moduleinfo' %}?page={{ page|add:-1 }}&category={{ category }}&search={{ search }}" class="hint hint-top" data-hint="上一页"><span class="glyphicon glyphicon-step-backward"></span></a>
            {% endifnotequal %}
            {% ifnotequal page page_total %}&nbsp;
            <a href="{% url  'business:moduleinfo' %}?page={{ page|add:1 }}&category={{ category }}&search={{ search }}" class="hint hint-top" data-hint="下一页"><span class="glyphicon glyphicon-step-forward"></span></a>
            {% endifnotequal %}&nbsp;
            <a class="word hint hint-top" data-hint="尾页" href="{% url 'business:moduleinfo' %}?page={{ page_total }}&category={{ category }}&search={{ search }}"><span class="glyphicon glyphicon-fast-forward"></span></a>

        </span>
    </div>
</div>

<!-- 模态框（Modal）编辑用户资料 -->
<div class="modal fade" id="lookItem" tabindex="-1" role="dialog" aria-labelledby="lookItemLabel">
    <div class="modal-dialog">
        <div class="modal-content" style="width:800px">
            <div class="modal-header">
                <button type="button" class="close"
                        data-dismiss="modal">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    详情
                </h4>
            </div>
            <div class="modal-body item_details">
                <b>模块详情</b>
                <table class="table table-bordered table-hover">
                    <thead>
                        <td class="col1">模块名</td>
                        <td class="col2">分类</td>
                        <td class="col3">父分类</td>
                        <td class="col4">项目/业务</td>
                        <td class="col5">应用</td>
                    </thead>
                    <tr>
                        <td class="col1" id="module_name"></td>
                        <td class="col2" id="category_name"></td>
                        <td class="col3" id="parent_category_name"></td>
                        <td class="col4" id="project"></td>
                        <td class="col5" id="application"></td>
                    </tr>
                </table>
                <table class="table table-bordered table-hover">
                    <thead>
                        <td class="col1">负责人</td>
                        <td class="col2">备负责人</td>
                        <td colspan="3">备注</td>
                    </thead>
                    <tr>
                        <td class="col1" id="responser"></td>
                        <td class="col2" id="responser_back"></td>
                        <td colspan="3" id="comment"></td>
                    </tr>
                </table>

                <b>设备配置</b>
                <table class="table table-bordered table-hover">
                    <thead>
                        <td>系统IP</td>
                        <td>应用目录</td>
                        <td>server端口</td>
                        <td>状态</td>
                    </thead>
                    <tbody id="moduleInfo">

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(".pagei").change(function(){
        var index=$(this).children('option:selected').val();
        window.location.href="{% url 'business:moduleinfo' %}?page=" + index + "&category={{ category }}&search={{ search }}";
    });

    $(".edit_item").click(function(){
    　　var module_no = $(this).data("bno");
        window.location.href="{% url 'business:meditinfo' %}?page="+{{ page }} + "&module_no=" +module_no;
    });
    $(".delete_item").click(function(){
        if(confirm("确定要删除吗？删除操作不可恢复！")) {
            var id = $(this).data("id");
            var module_no = $(this).data("bno");
            var urls = "{% url 'business:mdeleteaction' %}";
            var postdata = {id:id,module_no:module_no}
            var jsonstr = $.ajax({
                url : urls,
                type : "POST",
                data : postdata,
                async : false,
                cache : false
		    });
		    var jsonobj = eval('(' + jsonstr.responseText + ')');
		    if(jsonobj.status == 0){
	            alert(jsonobj.message);
	        }else{
	            window.location.reload();
	    }
	    }
    });

    $("#lookItem").on('show.bs.modal',function(event){
        var button = $(event.relatedTarget);
        var bno = button.data("bno");
        var urls = "{% url 'business:moduleget' %}";
        postdata = {module_no:bno};
        var jsonstr = $.ajax({
			url : urls,
			type : "POST",
			data : postdata,
			async : false,
			cache : false
		});
		var jsonobj = eval('(' + jsonstr.responseText + ')');
		if(jsonobj.status == 0){
		    alert(jsonobj.message);
		}else{
		    $(this).find('#module_name').html(jsonobj.data.business_info.module_name);
		    $(this).find('#category_name').html(jsonobj.data.business_info.category_name);
		    $(this).find('#parent_category_name').html(jsonobj.data.business_info.parent_category_name);
		    $(this).find('#project').html(jsonobj.data.business_info.project);
		    $(this).find('#application').html(jsonobj.data.business_info.application);
		    $(this).find('#responser').html(jsonobj.data.business_info.responser);
		    $(this).find('#responser_back').html(jsonobj.data.business_info.responser_back);
		    $(this).find('#comment').html(jsonobj.data.business_info.comment);
		    $(this).find('tbody#moduleInfo').html('');
		    if(typeof(jsonobj.data.server_mapping_list) != "undefined"){
		        for(var idx in jsonobj.data.server_mapping_list){
		            tmpMapping = jsonobj.data.server_mapping_list[idx]
		            $(this).find('tbody#moduleInfo').append('<tr><td>' + tmpMapping['sys_ip_inner'] + '</td>'
		            + '<td> '+ tmpMapping['application_path'] + '</td>'
		            + '<td>' + tmpMapping['server_port'] + '</td>'
		            + '<td>' + tmpMapping['use_status_desc'] + '</td></tr>');
		        }
		    }
		}
    });

    $("#searchModule").click(function(){
        var search = $("#search").val();
        var category = $("#category").val();

        window.location.href="{% url 'business:moduleinfo' %}?page=" +{{ page }} + "&category=" + category + "&search=" + search;
    });
</script>
{% endblock %}

